package com.bungarus.group.model;

import org.springframework.stereotype.Component;

import java.io.Serializable;

/**
 * Created by tang on 2018/12/2.
 */
@Component
public class GroupMember implements Serializable {
    private long gid;
    private String gName;
    private long mid;
    private String mName;
    private String mAccount;
    private long tenantId;

    public static GroupMember ofGroup(Group group) {
        GroupMember gm = new GroupMember();
        gm.setGid(group.get_id());
        gm.setTenantId(group.getTenantId());
        gm.setgName(null == group.getName()?"":group.getName());
        return gm;
    }

    public static GroupMember ofMember(Member member) {
        GroupMember gm = new GroupMember();
        gm.setMid(member.getId());
        gm.setTenantId(member.getTenantId());
        gm.setmAccount(null == member.getAccountName()?"":member.getAccountName());
        gm.setmName(null == member.getName()?"":member.getName());
        return gm;
    }

    public static GroupMember ofGroupAndMember(Group group, Member member) {
        GroupMember gm = new GroupMember();
        gm.setGid(group.get_id());
        gm.setgName(group.getName());
        gm.setMid(member.getId());
        gm.setmName(member.getName());
        gm.setmAccount(member.getAccountName());
        gm.setTenantId(group.getTenantId());
        return gm;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof GroupMember)) return false;

        GroupMember that = (GroupMember) o;

        if (getGid() != that.getGid()) return false;
        return getMid() == that.getMid();

    }

    @Override
    public int hashCode() {
        int result = (int) (getGid() ^ (getGid() >>> 32));
        result = 31 * result + (int) (getMid() ^ (getMid() >>> 32));
        return result;
    }

    public String getgName() {
        return gName;
    }

    public void setgName(String gName) {
        this.gName = gName;
    }

    public String getmName() {
        return mName;
    }

    public void setmName(String mName) {
        this.mName = mName;
    }

    public long getTenantId() {
        return tenantId;
    }

    public void setTenantId(long tenantId) {
        this.tenantId = tenantId;
    }

    public long getGid() {
        return gid;
    }

    public void setGid(long gid) {
        this.gid = gid;
    }

    public long getMid() {
        return mid;
    }

    public void setMid(long mid) {
        this.mid = mid;
    }

    public String getmAccount() {
        return mAccount;
    }

    public void setmAccount(String mAccount) {
        this.mAccount = mAccount;
    }
}
